```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>反转链表算法解析</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', 'Noto Serif SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8f9fa;
            color: #333;
            line-height: 1.6;
        }
        .hero {
            background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
            color: white;
        }
        .code-block {
            background-color: #282c34;
            border-radius: 8px;
            position: relative;
        }
        .code-header {
            background-color: #1e2127;
            border-top-left-radius: 8px;
            border-top-right-radius: 8px;
            padding: 8px 12px;
            color: #abb2bf;
            font-size: 0.9rem;
            display: flex;
            justify-content: space-between;
        }
        .code-copy-btn {
            background: none;
            border: none;
            color: #abb2bf;
            cursor: pointer;
            transition: all 0.2s;
        }
        .code-copy-btn:hover {
            color: white;
        }
        pre {
            margin: 0;
            padding: 16px;
            overflow-x: auto;
        }
        .code-highlight {
            color: #abb2bf;
        }
        .keyword { color: #c678dd; }
        .type { color: #e06c75; }
        .string { color: #98c379; }
        .comment { color: #5c6370; font-style: italic; }
        .method { color: #61afef; }
        .card-hover {
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
        }
        .solution-card {
            border-left: 4px solid;
            transition: all 0.3s ease;
        }
        .iterative {
            border-left-color: #2575fc;
        }
        .recursive {
            border-left-color: #6a11cb;
        }
        .mermaid {
            background-color: white;
            border-radius: 8px;
            padding: 20px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        .linked-list {
            display: flex;
            justify-content: center;
            align-items: center;
            margin: 20px 0;
        }
        .node {
            width: 50px;
            height: 50px;
            background-color: #6a11cb;
            color: white;
            border-radius: 50%;
            display: flex;
            justify-content: center;
            align-items: center;
            margin: 0 10px;
            position: relative;
            font-weight: bold;
        }
        .arrow {
            width: 30px;
            height: 3px;
            background-color: #333;
            position: relative;
        }
        .arrow:after {
            content: '';
            position: absolute;
            right: 0;
            top: -5px;
            width: 0;
            height: 0;
            border-left: 10px solid #333;
            border-top: 5px solid transparent;
            border-bottom: 5px solid transparent;
        }
        .pointer {
            background-color: #e06c75;
            color: white;
            padding: 4px 8px;
            border-radius: 4px;
            font-size: 0.8rem;
            position: absolute;
            top: -25px;
            left: 50%;
            transform: translateX(-50%);
            white-space: nowrap;
        }
    </style>
</head>
<body class="min-h-screen">
    <!-- Hero Section -->
    <section class="hero py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl text-center">
            <h1 class="text-4xl md:text-5xl font-bold mb-6 animate-fadeIn">反转链表算法解析</h1>
            <p class="text-xl md:text-2xl opacity-90 mb-8">深入理解指针操作与递归的经典案例</p>
            <div class="flex justify-center">
                <div class="linked-list" id="animated-list">
                    <div class="node">1</div>
                    <div class="arrow"></div>
                    <div class="node">2</div>
                    <div class="arrow"></div>
                    <div class="node">3</div>
                    <div class="arrow"></div>
                    <div class="node">4</div>
                    <div class="arrow"></div>
                    <div class="node">5</div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 md:px-0 py-12">
        <!-- Problem Description -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden p-6 card-hover">
                <div class="flex items-center mb-4">
                    <i class="fas fa-question-circle text-2xl text-purple-600 mr-3"></i>
                    <h2 class="text-2xl font-bold">题目描述</h2>
                </div>
                <p class="text-lg mb-4">反转一个单链表。例如，输入链表 1→2→3→4→5，反转后变为 5→4→3→2→1。</p>
                <div class="bg-yellow-50 border-l-4 border-yellow-400 p-4">
                    <div class="flex">
                        <div class="flex-shrink-0">
                            <i class="fas fa-lightbulb text-yellow-500"></i>
                        </div>
                        <div class="ml-3">
                            <p class="text-sm text-yellow-700">
                                <strong>要求：</strong>一次遍历完成（即时间复杂度为 O(n)）
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Core Concepts -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 flex items-center">
                <i class="fas fa-brain text-purple-600 mr-3"></i>
                <span>核心考点与算法</span>
            </h2>
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md overflow-hidden p-6 card-hover">
                    <h3 class="text-xl font-bold mb-4 text-blue-600">指针操作</h3>
                    <p>通过改变节点之间的指针指向来实现链表的反转，需要精确控制多个指针的移动和更新。</p>
                </div>
                <div class="bg-white rounded-xl shadow-md overflow-hidden p-6 card-hover">
                    <h3 class="text-xl font-bold mb-4 text-purple-600">递归</h3>
                    <p>利用递归的特性，从链表尾部开始反转，需要理解递归的调用栈和返回过程。</p>
                </div>
            </div>
        </section>

        <!-- Solution Approaches -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 flex items-center">
                <i class="fas fa-code text-purple-600 mr-3"></i>
                <span>解题思路</span>
            </h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <!-- Iterative Solution -->
                <div class="bg-white rounded-lg overflow-hidden solution-card iterative card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <i class="fas fa-sync-alt text-blue-600 text-2xl mr-3"></i>
                            <h3 class="text-xl font-bold">迭代法</h3>
                        </div>
                        <p class="mb-4">使用三个指针（<code class="bg-gray-100 px-1 rounded">prev</code>, <code class="bg-gray-100 px-1 rounded">curr</code>, <code class="bg-gray-100 px-1 rounded">next</code>），逐个反转节点的指向。</p>
                        <div class="flex flex-wrap gap-2 mb-4">
                            <span class="bg-blue-100 text-blue-800 text-xs font-medium px-2.5 py-0.5 rounded">时间复杂度 O(n)</span>
                            <span class="bg-green-100 text-green-800 text-xs font-medium px-2.5 py-0.5 rounded">空间复杂度 O(1)</span>
                        </div>
                        
                        <div class="mt-6">
                            <div class="code-block">
                                <div class="code-header">
                                    <span>Java</span>
                                    <button class="code-copy-btn">
                                        <i class="far fa-copy"></i>
                                    </button>
                                </div>
                                <pre><code class="code-highlight">
<span class="keyword">public</span> <span class="type">ListNode</span> <span class="method">reverseList</span>(<span class="type">ListNode</span> head) {
    <span class="comment">// 前一个节点指针，初始为null</span>
    <span class="type">ListNode</span> prev = <span class="keyword">null</span>;
    <span class="comment">// 当前节点指针，初始为头节点</span>
    <span class="type">ListNode</span> curr = head;
    
    <span class="comment">// 遍历链表</span>
    <span class="keyword">while</span> (curr != <span class="keyword">null</span>) {
        <span class="comment">// 保存下一个节点，因为我们要改变当前节点的next指针</span>
        <span class="type">ListNode</span> nextTemp = curr.next;
        
        <span class="comment">// 反转当前节点的指针，指向前一个节点</span>
        curr.next = prev;
        
        <span class="comment">// 更新指针，准备处理下一个节点</span>
        prev = curr;      <span class="comment">// 前一个节点变为当前节点</span>
        curr = nextTemp;  <span class="comment">// 当前节点变为保存的下一个节点</span>
    }
    
    <span class="comment">// 返回新的头节点（原链表的尾节点）</span>
    <span class="keyword">return</span> prev;
}
                                </code></pre>
                            </div>
                        </div>
                    </div>
                </div>
                
                <!-- Recursive Solution -->
                <div class="bg-white rounded-lg overflow-hidden solution-card recursive card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <i class="fas fa-sitemap text-purple-600 text-2xl mr-3"></i>
                            <h3 class="text-xl font-bold">递归法</h3>
                        </div>
                        <p class="mb-4">递归到链表尾部，反转后返回新头节点，逐层调整指针。</p>
                        <div class="flex flex-wrap gap-2 mb-4">
                            <span class="bg-blue-100 text-blue-800 text-xs font-medium px-2.5 py-0.5 rounded">时间复杂度 O(n)</span>
                            <span class="bg-red-100 text-red-800 text-xs font-medium px-2.5 py-0.5 rounded">空间复杂度 O(n)</span>
                        </div>
                        
                        <div class="mt-6">
                            <div class="code-block">
                                <div class="code-header">
                                    <span>Java</span>
                                    <button class="code-copy-btn">
                                        <i class="far fa-copy"></i>
                                    </button>
                                </div>
                                <pre><code class="code-highlight">
<span class="keyword">public</span> <span class="type">ListNode</span> <span class="method">reverseListRecursive</span>(<span class="type">ListNode</span> head) {
    <span class="comment">// 基本情况：空链表或只有一个节点的链表</span>
    <span class="keyword">if</span> (head == <span class="keyword">null</span> || head.next == <span class="keyword">null</span>) {
        <span class="keyword">return</span> head;
    }
    
    <span class="comment">// 递归反转剩余部分，并获取新的头节点</span>
    <span class="type">ListNode</span> newHead = reverseListRecursive(head.next);
    
    <span class="comment">// 将当前节点的下一个节点指向当前节点，形成反向连接</span>
    head.next.next = head;
    
    <span class="comment">// 断开当前节点的原始连接，防止形成环</span>
    head.next = <span class="keyword">null</span>;
    
    <span class="comment">// 返回新的头节点</span>
    <span class="keyword">return</span> newHead;
}
                                </code></pre>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Visualization Section -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 flex items-center">
                <i class="fas fa-project-diagram text-purple-600 mr-3"></i>
                <span>算法可视化</span>
            </h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md overflow-hidden p-6 card-hover">
                    <h3 class="text-xl font-bold mb-4">迭代法指针变化</h3>
                    <div class="mermaid">
                        graph LR
                            A[初始化: prev=null, curr=head] --> B{curr != null?}
                            B -- 是 --> C[保存next: nextTemp=curr.next]
                            C --> D[反转指针: curr.next=prev]
                            D --> E[移动指针: prev=curr, curr=nextTemp]
                            E --> B
                            B -- 否 --> F[返回prev]
                    </div>
                </div>
                <div class="bg-white rounded-xl shadow-md overflow-hidden p-6 card-hover">
                    <h3 class="text-xl font-bold mb-4">递归法调用栈</h3>
                    <div class="mermaid">
                        graph TD
                            A[reverse(1→2→3→4→5)] --> B[reverse(2→3→4→5)]
                            B --> C[reverse(3→4→5)]
                            C --> D[reverse(4→5)]
                            D --> E[reverse(5)]
                            E -->|返回5| D
                            D -->|5→4,4→null| C
                            C -->|5→4→3,3→null| B
                            B -->|5→4→3→2,2→null| A
                            A -->|5→4→3→2→1,1→null| 结束
                    </div>
                </div>
            </div>
        </section>

        <!-- Interactive Demo -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 flex items-center">
                <i class="fas fa-play-circle text-purple-600 mr-3"></i>
                <span>交互式演示</span>
            </h2>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden p-6 card-hover">
                <div class="flex justify-between items-center mb-6">
                    <h3 class="text-xl font-bold">迭代法指针移动过程</h3>
                    <button id="demo-btn" class="bg-purple-600 hover:bg-purple-700 text-white font-medium py-2 px-4 rounded-md transition duration-300">
                        <i class="fas fa-play mr-2"></i>开始演示
                    </button>
                </div>
                
                <div class="flex justify-center">
                    <div class="linked-list" id="demo-list">
                        <div class="node">1</div>
                        <div class="arrow"></div>
                        <div class="node">2</div>
                        <div class="arrow"></div>
                        <div class="node">3</div>
                        <div class="arrow"></div>
                        <div class="node">4</div>
                        <div class="arrow"></div>
                        <div class="node">5</div>
                    </div>
                </div>
                
                <div class="mt-6">
                    <div class="flex justify-center space-x-8">
                        <div class="text-center">
                            <div class="pointer" id="prev-pointer">prev</div>
                            <div class="w-10 h-10 rounded-full bg-red-500 flex items-center justify-center text-white mx-auto">p</div>
                        </div>
                        <div class="text-center">
                            <div class="pointer" id="curr-pointer">curr</div>
                            <div class="w-10 h-10 rounded-full bg-blue-500 flex items-center justify-center text-white mx-auto">c</div>
                        </div>
                        <div class="text-center">
                            <div class="pointer" id="next-pointer">next</div>
                            <div class="w-10 h-10 rounded-full bg-green-500 flex items-center justify-center text-white mx-auto">n</div>
                        </div>
                    </div>
                </div>
                
                <div class="mt-8">
                    <div class="bg-gray-100 p-4 rounded-md">
                        <h4 class="font-bold mb-2">当前步骤说明：</h4>
                        <p id="demo-description">点击"开始演示"按钮查看迭代法反转链表的过程。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- ListNode Definition -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 flex items-center">
                <i class="fas fa-cube text-purple-600 mr-3"></i>
                <span>链表节点定义</span>
            </h2>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                <div class="code-block">
                    <div class="code-header">
                        <span>Java</span>
                        <button class="code-copy-btn">
                            <i class="far fa-copy"></i>
                        </button>
                    </div>
                    <pre><code class="code-highlight">
<span class="comment">/**
 * 链表节点定义
 */</span>
<span class="keyword">public</span> <span class="keyword">class</span> <span class="type">ListNode</span> {
    <span class="keyword">int</span> val;
    <span class="type">ListNode</span> next;
    
    <span class="comment">// 构造函数</span>
    <span class="method">ListNode</span>() {}
    <span class="method">ListNode</span>(<span class="keyword">int</span> val) { <span class="keyword">this</span>.val = val; }
    <span class="method">ListNode</span>(<span class="keyword">int</span> val, <span class="type">ListNode</span> next) { <span class="keyword">this</span>.val = val; <span class="keyword">this</span>.next = next; }
}
                    </code></pre>
                </div>
            </div>
        </section>
    </main>

    <script>
        // Initialize Mermaid
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });

        // Interactive demo functionality
        document.addEventListener('DOMContentLoaded', function() {
            const demoBtn = document.getElementById('demo-btn');
            const demoList = document.getElementById('demo-list');
            const nodes = demoList.querySelectorAll('.node');
            const arrows = demoList.querySelectorAll('.arrow');
            const prevPointer = document.getElementById('prev-pointer');
            const currPointer = document.getElementById('curr-pointer');
            const nextPointer = document.getElementById('next-pointer');
            const demoDescription = document.getElementById('demo-description');
            
            const steps = [
                {
                    description: "初始状态：prev = null, curr = 节点1",
                    prevPos: -1,
                    currPos: 0,
                    nextPos: 1
                },
                {
                    description: "保存next指针：nextTemp = 节点2",
                    prevPos: -1,
                    currPos: 0,
                    nextPos: 1
                },
                {
                    description: "反转指针：节点1.next = prev (null)",
                    prevPos: -1,
                    currPos: 0,
                    nextPos: 1,
                    changeArrow: 0,
                    newArrowDirection: 'none'
                },
                {
                    description: "移动指针：prev = 节点1, curr = 节点2",
                    prevPos: 0,
                    currPos: 1,
                    nextPos: 2
                },
                {
                    description: "保存next指针：nextTemp = 节点3",
                    prevPos: 0,
                    currPos: 1,
                    nextPos: 2
                },
                {
                    description: "反转指针：节点2.next = prev (节点1)",
                    prevPos: 0,
                    currPos: 1,
                    nextPos: 2,
                    changeArrow: 1,
                    newArrowDirection: 'left'
                },
                {
                    description: "移动指针：prev = 节点2, curr = 节点3",
                    prevPos: 1,
                    currPos: 2,
                    nextPos: 3
                },
                {
                    description: "保存next指针：nextTemp = 节点4",
                    prevPos: 1,
                    currPos: 2,
                    nextPos: 3
                },
                {
                    description: "反转指针：节点3.next = prev (节点2)",
                    prevPos: 1,
                    currPos: 2,
                    nextPos: 3,
                    changeArrow: 2,
                    newArrowDirection: 'left'
                },
                {
                    description: "移动指针：prev = 节点3, curr = 节点4",
                    prevPos: 2,
                    currPos: 3,
                    nextPos: 4
                },
                {
                    description: "保存next指针：nextTemp = 节点5",
                    prevPos: 2,
                    currPos: 3,
                    nextPos: 4
                },
                {
                    description: "反转指针：节点4.next = prev (节点3)",
                    prevPos: 2,
                    currPos: 3,
                    nextPos: 4,
                    changeArrow: 3,
                    newArrowDirection: 'left'
                },
                {
                    description: "移动指针：prev = 节点4, curr = 节点5",
                    prevPos: 3,
                    currPos: 4,
                    nextPos: 5
                },
                {
                    description: "保存next指针：nextTemp = null",
                    prevPos: 3,
                    currPos: 4,
                    nextPos: -1
                },
                {
                    description: "反转指针：节点5.next = prev (节点4)",
                    prevPos: 3,
                    currPos: 4,
                    nextPos: -1,
                    changeArrow: 4,
                    newArrowDirection: 'left'
                },
                {
                    description: "移动指针：prev = 节点5, curr = null",
                    prevPos: 4,
                    currPos: -1,
                    nextPos: -1
                },
                {
                    description: "循环结束，返回prev (节点5) 作为新链表的头节点",
                    prevPos: 4,
                    currPos: -1,
                    nextPos: -1
                }
            ];
            
            let currentStep = 0;
            let isAnimating = false;
            
            demoBtn.addEventListener('click', function() {
                if (isAnimating) return;
                
                if (currentStep === 0) {
                    demoBtn.innerHTML = '<i class="fas fa-forward mr-2"></i>下一步';
                }
                
                if (currentStep >= steps.length) {
                    // Reset animation
                    currentStep = 0;
                    resetDemo();
                    demoBtn.innerHTML = '<i class="fas fa-play mr-2"></i>开始演示';
                    return;
                }
                
                isAnimating = true;
                const step = steps[currentStep];
                
                // Update pointers
                updatePointer(prevPointer, step.prevPos);
                updatePointer(currPointer, step.currPos);
                updatePointer(nextPointer, step.nextPos);
                
                // Update arrow if needed
                if (step.changeArrow !== undefined) {
                    const arrow = arrows[step.changeArrow];
                    if (step.newArrowDirection === 'left') {
                        arrow.style.transform = 'rotate(180deg)';
                        arrow.style.backgroundColor = '#6a11cb';
                        arrow.after.style.borderLeftColor = '#6a11cb';
                    } else if (step.newArrowDirection === 'none') {
                        arrow.style.opacity = '0';
                    }
                }
                
                // Update description
                demoDescription.textContent = step.description;
                
                // Highlight current node if applicable
                if (step.currPos >= 0 && step.currPos < nodes.length) {
                    nodes.forEach(node => node.style.backgroundColor = '#6a11cb');
                    nodes[step.currPos].style.backgroundColor = '#2575fc';
                }
                
                currentStep++;
                
                setTimeout(() => {
                    isAnimating = false;
                    
                    if (currentStep === steps.length) {
                        demoBtn.innerHTML = '<i class="fas fa-redo mr-2"></i>重新开始';
                    }
                }, 800);
            });
            
            function updatePointer(pointer, pos) {
                if (pos === -1) {
                    pointer.style.display = 'none';
                } else {
                    pointer.style.display = 'block';
                    const node = nodes[pos];
                    const rect = node.getBoundingClientRect();
                    const listRect = demoList.getBoundingClientRect();
                    
                    pointer.style.left = `${rect.left - listRect.left + rect.width/2}px`;
                }
            }
            
            function resetDemo() {
                // Reset pointers
                prevPointer.style.display = 'none';
                currPointer.style.display = 'none';
                nextPointer.style.display = 'none';
                
                // Reset arrows
                arrows.forEach(arrow => {
                    arrow.style.transform = '';
                    arrow.style.backgroundColor = '#333';
                    arrow.style.opacity = '1';
                    if (arrow.after) {
                        arrow.after.style.borderLeftColor = '#333';
                    }
                });
                
                // Reset nodes
                nodes.forEach(node => {
                    node.style.backgroundColor = '#6a11cb';
                });
                
                // Reset description
                demoDescription.textContent = '点击"开始演示"按钮查看迭代法反转链表的过程。';
            }
            
            // Copy button functionality
            document.querySelectorAll('.code-copy-btn').forEach(button => {
                button.addEventListener('click', function() {
                    const codeBlock = this.closest('.code-block').querySelector('pre code');
                    const codeText = codeBlock.textContent;
                    
                    navigator.clipboard.writeText(codeText).then(() => {
                        const originalIcon = this.innerHTML;
                        this.innerHTML = '<i class="fas fa-check"></i>';
                        
                        setTimeout(() => {
                            this.innerHTML = originalIcon;
                        }, 2000);
                    });
                });
            });
        });
    </script>
</body>
</html>
```